package com.etone.smartAudit.controller;

import com.etone.smartAudit.annotation.LoginAdmin;
import com.etone.smartAudit.domain.Admin;
import com.etone.smartAudit.service.AuditExceptionCityReportService;
import com.etone.smartAudit.vo.auditExceptionCityReport.AuditExceptionCityReportVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author: sovy
 * @date: 2021/1/18
 * @description:
 */
@AllArgsConstructor
@RestController
@Api(tags = "地市报告", value = "AuditExceptionCityReportController")
public class AuditExceptionCityReportController {

    private AuditExceptionCityReportService auditExceptionCityReportService;

    @ApiOperation(value = "下载报表，扩展名为zip《完》")
    @GetMapping("/areaReports/export")
    public void export(
            @ApiParam(value = "期数，示例:2021年第一期") @RequestParam String reportPeriods,
            @ApiParam(value = "地市") @RequestParam List<String> areas,
            @ApiParam(value = "参数字段") @RequestParam(required = false) List<String> fields,
            @ApiIgnore @LoginAdmin Admin admin) {
        auditExceptionCityReportService.batchExportReport(fields, reportPeriods, areas, admin);
    }

    @ApiOperation(value = "导出单个报表，扩展名为docx《完》")
    @GetMapping("/areaReports/{id}/export")
    public void export(
            @ApiParam(value = "id") @PathVariable Integer id,
            @ApiParam(value = "参数字段") @RequestParam(required = false) List<String> fields,
            HttpServletResponse response
    ) {
        auditExceptionCityReportService.exportReport(id, fields, response);
    }

    @ApiOperation(value = "获取所有城市列表《完》")
    @GetMapping("/areaReports/cities")
    public List<String> findAllCity() {
        return auditExceptionCityReportService.findAllCity();
    }

    @ApiOperation(value = "获取所有地市报告列表《完》")
    @GetMapping("/areaReports")
    public AuditExceptionCityReportVO list(
            @ApiParam(value = "地市名称") @RequestParam(required = false) String cityName,
            @ApiParam(value = "月份，格式yyyy-MM") @RequestParam(required = false) String date,
            @ApiParam(value = "当前页") @RequestParam(required = false, defaultValue = "1") int page,
            @ApiParam(value = "每页显示数量") @RequestParam(required = false, defaultValue = "10") int pageSize
    ) {
        return auditExceptionCityReportService.list(cityName, date, page, pageSize);
    }

    @ApiOperation(value = "地市风险扫描报告《完》")
    @GetMapping("/areaReports/exception/batchExport")
    public void cityExceptionReportBatchExport(
            @ApiParam(value = "开始月份，格式yyyy-MM") @RequestParam(required = false) String startTime,
            @ApiParam(value = "结束月份，格式yyyy-MM") @RequestParam(required = false) String endTime,
            @ApiParam(value = "地市名称,多个地市逗号隔开") @RequestParam(required = false) List<String> citys,
            @ApiIgnore @LoginAdmin Admin admin
            ) {
        auditExceptionCityReportService.cityExceptionReportBatchExport(startTime, endTime, citys,admin);
    }
}
